package com.qingke.mapping;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.SqlSession;

import com.qingke.Player;
import com.qingke.pojo.Blog;
import com.qingke.pojo.User;
import com.qingke.projo.user;

public interface BlogMapper {

	@Insert("insert into blog(userId,title,content) values(#{userId},#{title},#{content})")
	@Options(keyProperty="id", useGeneratedKeys=true)
	void inserBlog(Blog blog);
	
	@Update("update blog set userId=#{userId}, title=#{title} ,content=#{content} where id =#{id}")
	void update(Blog blog);
	
	@Delete("delete from blog where id =#{id} ")
	void delect(int id);
	
	@Select("select *from blog")
	List<Blog> findAllBlogs();
	
	@Select("select * from blog where userId = #{id}")
	List<Blog> findAllBolgs2();
	
	@Select("select * from blog where id = #{id}")
	@Results(value={
			@Result(property = "id",column="id"),
			@Result(property = "userId",column="userId"),
			@Result(property = "title",column="title"),
			@Result(property = "content",column="content"),
			@Result(property = "author",column="userId",javaType=User.class,
			one=@One(select ="com.qingke.mapping.userMapper.selectById")
					),
	})
	Blog findBlogId(int id);
	
	//SqlSession sql = Player.getI().gett();
	//BlogMapper bg = sql.getMapper(BlogMapper.class);
	//Blog blog = new Blog();
	
}
